/**
 * 
 */
package net.betou.trade.main.manager.impl;

import net.betou.common.hibernate3.Updater;
import net.betou.trade.entity.main.AgentAndAdmins;
import net.betou.trade.entity.main.Funds;
import net.betou.trade.main.dao.FundsDao;
import net.betou.trade.main.manager.FundsMng;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 叶装装
 */
@Service
@Transactional
public class FundsMngImpl implements FundsMng{

	public Funds save( Funds funds, AgentAndAdmins bean ) {
		funds.setAdmin( bean );
		dao.save( funds );
		return funds;
	}

	public Funds update( Funds funds, AgentAndAdmins bean ) {
		Funds entity = dao.findById( bean.getId( ) );
		if( entity == null ){
			entity = save( funds, bean );
			bean.getFunds( ).add( entity );
			return entity;
		}else{
			Updater< Funds > updater = new Updater< Funds >( entity );
			entity.setSmsNum( funds.getSmsNum( ) );
			funds = dao.updateByUpdater( updater );
			return funds;
		}
	}

	@Autowired
	private FundsDao dao;

}
